home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / JForth / JTools / Appls / terminal.f < prev    next >
Encoding:
FORTH Source  |  1994-11-05  |  2.3 KB  |  109 lines

  1. \ Simple terminal emulator
  2. \
  3. \ Author: Phil Burk
  4. \ Copyright 1987 Delta Research
  5.  
  6. \ MOD: PLB 1989 Various improvements
  7. \ MOD: PLB 4/9/91 Fix stack in TERMINAL.TERM
  8.  
  9. \ 00001 05-Nov-94 mdh changed appropriate io_ struct members to ser_
  10. \                     baud-rate to 2400
  11.  
  12. getmodule includes
  13. include? io_message ji:exec/exec.j
  14. include? serial.open ju:serial
  15.  
  16. ANEW TASK-JTERM
  17.  
  18. CREATE READ-MESSAGE 20 allot
  19. VARIABLE TERM-BUF
  20. VARIABLE IORQ-WRITE
  21. VARIABLE IORQ-READ
  22. VARIABLE BAUD-RATE
  23. variable OLD-CONSOLE
  24. variable HALF-DUPLEX
  25. 2400 baud-rate !
  26.  
  27. : TERMINAL.SETUP ( serreq -- )
  28.     4096 over ..! ser_rbuflen
  29.     7 over ..! ser_ReadLen
  30.     7 over ..! ser_WriteLen
  31.     baud-rate @ over ..! ser_Baud
  32.     0 over ..! ser_Serflags
  33.     2 over ..! ser_stopbits
  34.     serial.setparams .hex
  35. ;
  36.  
  37. : TERMINAL.INIT  ( -- , open serial devices )
  38.     old-console off
  39.     " RAW:0/10/640/100/JForth Terminal" $fopen ?dup
  40.     IF  console@ old-console !  ( save original console )
  41.         console!
  42.     THEN
  43.     SERF_SHARED 0" ser-read" serial.open .hex iorq-read !
  44.     SERF_SHARED 0" ser-write" serial.open .hex iorq-write !
  45.     iorq-read @ terminal.setup
  46.     iorq-write @ terminal.setup cr
  47. ;
  48.  
  49. : TERMINAL.TERM  ( -- , restore original window, close serial )
  50.     old-console @ ?dup
  51.     IF
  52.         console@   fclose
  53.         console!  
  54.     THEN
  55.     iorq-read @ serial.close
  56.     iorq-write @ serial.close
  57. ;
  58.  
  59. : TERMINAL.START.READ ( -- )
  60.     read-message 1 iorq-read @ serial.read.async
  61. ;
  62.  
  63. : TERMINAL.FINISH.READ ( -- )
  64.     iorq-read @ waitio() ?dup
  65.     IF ." Read error = " .hex cr
  66.     THEN
  67. \    read-message c@ dup ." Recieved = " emit space .hex cr
  68.     read-message c@ emit flushemit
  69. ;
  70.  
  71. : TERMINAL.READ  ( -- , print any characters read )
  72.     iorq-read @ checkio()
  73.     IF 
  74.        terminal.finish.read
  75.        terminal.start.read
  76.     THEN
  77. ;
  78.  
  79. : TERMINAL.ABORT.READ
  80.     iorq-read @ abortio() .hex
  81. ;
  82.  
  83. : TERMINAL.WRITE ( -- done?, send any characters hit to serial )
  84.     ?terminal
  85.     IF key dup ascii ~ =
  86.         IF drop true
  87.         ELSE half-duplex @
  88.              IF dup emit flushemit
  89.              THEN
  90.              term-buf c! term-buf 1 iorq-write @
  91.              serial.write drop ( returns strange errors! )
  92.              false
  93.         THEN
  94.     ELSE false
  95.     THEN
  96. ;
  97.  
  98. : TERMINAL ( -- )
  99.     terminal.init
  100.     terminal.start.read
  101.     BEGIN
  102.         terminal.read
  103.         terminal.write
  104.     UNTIL
  105.     terminal.abort.read
  106.     terminal.term
  107. ;
  108.  
  109.